package com.tutu.category.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tutu.category.mapper.CategoryMapper;
import com.tutu.category.service.CategoryService;
import com.tutu.commons.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Program: b2c-cloud-store
 * @Description:
 * @Author: JK.TuTu
 * @Version: 1.0
 * @Create: 2022-12-15 11:16
 **/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 根据类别名称获取类别信息
     * @param categoryName 类别名称
     * @return 返回结果实体对象
     */
    @Override
    public Category getCategoryByName(String categoryName) {
        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Category::getCategoryName,categoryName);
        return categoryMapper.selectOne(queryWrapper);
    }

    /**
     * 获取所有商品分类
     * @return 所有商品分类集合
     */
    @Override
    public List<Category> getAll() {
        return categoryMapper.selectList(null);
    }
}
